const app = getApp();
Page({

  data: {
    deviceName:"",
    deviceCode:null,
    alarmFastBreath:0,     // 呼吸过快
    alarmFastHeart:0,      // 心跳过快
    alarmNoHeart:0,        // 无心跳
    alarmOpen:0,           // 报警开关
    alarmSlowBreath:0,     // 呼吸过慢
    alarmSlowHeart:0,      // 心跳过慢
    alarmPhone:0           // 设置报警电话
  },

  watchValue(e){
    let that = this;
    console.log(e.detail.value,e,that.data.deviceCode)

    wx.request({
      url: app.globalData.url + 'renameUserDevice',
      data:{
        deviceName:e.detail.value,
        deviceCode:that.data.deviceCode
      },
      method:'POST',
      header:{
        token:app.globalData.token
      },
      success:function(res){
        console.log("重命名成功======",res);
        // that.getDeviceList();
      }
    })

  },


  confim_sub(){
    this.deviceSetting();
  },
  // 无心跳
  bindnoheart(e){
    this.setData({
      alarmNoHeart:e.detail.value
    })
  },

  //心率过快
  bindfastheart(e){
    this.setData({
      alarmFastHeart:e.detail.value
    })
  },
  //心率过慢
  bindslowheart(e){
    this.setData({
      alarmSlowHeart:e.detail.value
    })
  },
  //呼吸过快
  bindbreathfast(e){
    this.setData({
      alarmFastBreath:e.detail.value
    })
  },
  //呼吸过慢
  bindbreathslow(e){
    this.setData({
      alarmSlowBreath:e.detail.value
    })
  },

  //设置报警开关
  switchChange(e){

    console.log("设置报警开关======",e)

    if(e.detail.value == true){
      this.setData({
        alarmOpen:1
      })
    }else{
      this.setData({
        alarmOpen:0
      })
    }


  },



  //设置报警信息
  deviceSetting(){
    let that = this;
    console.log("=====kkkkk",that.data.alarmFastHeart);

    wx.request({
      url: app.globalData.url+'deviceSetting',
      data:{
        userDeviceName:that.data.deviceName,
        alarmFastBreath:that.data.alarmFastBreath,     // 呼吸过快
        alarmFastHeart:that.data.alarmFastHeart,       // 心跳过快
        alarmNoHeart:that.data.alarmFastHeart,         // 无心跳
        alarmOpen:that.data.alarmOpen,                 // 报警开关
        alarmSlowBreath:that.data.alarmSlowBreath,     // 呼吸过慢
        alarmSlowHeart:that.data.alarmSlowHeart,       // 心跳过慢
        alarmPhone:that.data.alarmPhone,               // 设置手机号
        deviceCode:that.data.deviceCode
      },
      method:"POST",
      header:{
        token:app.globalData.token
      },
      success:function(res){
        console.log("设置报警信息=====",res)
        if(res.data.code == 0){
          wx.showModal({
            title:'提示',
            content:res.data.msg,
            showCancel:false,
            success(res){
              if(res.confirm){
                // 确定
                wx.navigateBack({
                  delta: 1,
                })
              }else if(res.cancel){
                // 取消
              }
            }
          })
        }

      }
    })
  },

  onLoad: function (options) {
    console.log(options,"设置========");
    this.setData({
      deviceCode:options.deviceCode,
      deviceName:options.deviceName,
      alarmFastBreath:options.alarmFastBreath,
      alarmFastHeart:options.alarmFastHeart,
      alarmNoHeart:options.alarmNoHeart,
      alarmOpen:options.alarmOpen,
      alarmSlowBreath:options.alarmSlowBreath,
      alarmSlowHeart:options.alarmSlowHeart,
      alarmPhone:options.alarmPhone
    })
  },


  onReady: function () {
    
  },


  onShow: function () {
    
  },

  
  onHide: function () {
    
  },

  
  onUnload: function () {
    
  },

  
  onPullDownRefresh: function () {
    
  },

 
  onReachBottom: function () {
    
  },

 
  onShareAppMessage: function () {
    
  }


})